<?php

//require_once '/home/fabio/Development/symfony-1.4.3/lib/autoload/sfCoreAutoload.class.php';
require_once dirname(__FILE__) . '/../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php';

sfCoreAutoload::register();

class ProjectConfiguration extends sfProjectConfiguration {

    static protected $mailer = null; # Symfony mailer system

    public function setup() {
        $this->enablePlugins('sfDoctrinePlugin');
//        $this->enablePlugins('sfCKEditorPlugin');
        $this->enablePlugins('stOfcPlugin');
    $this->enablePlugins('sfDoctrineGuardPlugin');
  }

    /**
     * Returns the project mailer
     */
    static public function getMailer() {
        if (null !== self::$mailer) {
            return self::$mailer;
        }

        // If sfContext has instance, returns the classic mailer resource
        if (sfContext::hasInstance() && sfContext::getInstance()->getMailer()) {
            self::$mailer = sfContext::getInstance()->getMailer();
        } else {
            // Else, initialization
            if (!self::hasActive()) {
                throw new sfException('No sfApplicationConfiguration loaded');
            }
            require_once sfConfig::get('sf_symfony_lib_dir') . '/vendor/swiftmailer/classes/Swift.php';
            Swift::registerAutoload();
            sfMailer::initialize();
            $applicationConfiguration = self::getActive();

            $config = sfFactoryConfigHandler::getConfiguration($applicationConfiguration->getConfigPaths('config/factories.yml'));

            self::$mailer = new $config['mailer']['class']($applicationConfiguration->getEventDispatcher(), $config['mailer']['param']);
        }

        return self::$mailer;
    }

}
